package com.uwantsoft.business.infrastructure.repository;

import com.uwantsoft.business.facade.dto.parking.ParkOverviewQueryCondition;
import com.uwantsoft.business.infrastructure.repository.querier.ParkOverviewQuerier;
import com.uwantsoft.business.service.domain.park.Park;
import com.uwantsoft.business.service.infrastructure.ParkRepository;
import com.uwantsoft.util.HibernateEntityRepository;
import org.joda.time.DateTime;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author LeiPeichen.
 */
@Repository("hibernateParkRepository")
public class HibernateParkRepository extends HibernateEntityRepository implements ParkRepository{

    @Override
    public List<Park> findParks(ParkOverviewQueryCondition condition) {
        ParkOverviewQuerier parkOverviewQuerier = new ParkOverviewQuerier(getHibernateTemplate(),condition);
        return parkOverviewQuerier.getResults();
    }

    @Override
    public int findParkTotalAmount(ParkOverviewQueryCondition condition) {
        ParkOverviewQuerier parkOverviewQuerier = new ParkOverviewQuerier(getHibernateTemplate(), condition);
        return parkOverviewQuerier.getAmount();
    }

    @Override
    public int findParkAmount(DateTime todayStart,DateTime todayEnd) {
        List<Park> parkList = (List<Park>)getHibernateTemplate().find("from Park p where p.createTime between ? and ?",todayStart,todayEnd);
        return parkList.size();
    }

    @Override
    public List<Park> findParks(String region, String latitude, String longitude) {
        return null;
    }
}
